import {
	createRouter,
	createWebHistory
} from 'vue-router'
import { useUserStore } from '@/stores/counter'

const router = createRouter({
	history: createWebHistory(import.meta.env.BASE_URL),
	routes: [{
			path: '/',
			redirect: '/login'
		},
		{
			path: '/login',
			name: 'login',
			component: () => import("@/views/Login.vue")
		},
		{
			path: '/index',
			name: 'index',
			component: () => import("@/views/Index.vue"),
			redirect: '/welcome',
			children: [{
					path: '/welcome',
					name: 'welcome',
					component: () => import('@/views/Welcome.vue')
				},
				{
					path: '/ArticleClassification',
					name: 'ArticleClassification',
					component: () => import('@/views/ContentManagement/ArticleClassification.vue')
				},
				{
					path: '/ArticleManagement',
					name: 'ArticleManagement',
					component: () => import('@/views/ContentManagement/ArticleManagement.vue')
				},
				{
					path: '/FMclassification',
					name: 'FMclassification',
					component: () => import('@/views/ContentManagement/FMclassification.vue')
				},
				{
					path: '/FMmanagement',
					name: 'FMmanagement',
					component: () => import('@/views/ContentManagement/FMmanagement.vue')
				},
				{
					path: '/PublicWelfareCenter',
					name: 'PublicWelfareCenter',
					component: () => import('@/views/ContentManagement/PublicWelfareCenter.vue')
				},
				{
					path: '/PsychologicalKnowledge',
					name: 'PsychologicalKnowledge',
					component: () => import('@/views/ContentManagement/PsychologicalKnowledge.vue')
				},
				{
					path: '/ArticleRecycleBin',
					name: 'ArticleRecycleBin',
					component: () => import('@/views/ContentManagement/ArticleRecycleBin.vue')
				},
				{
					path: '/test',
					name: 'test',
					component: () => import('@/views/test.vue')
				},
				{
					path: '/CounselorInfo',
					name: 'CounselorInfo',
					component: () => import('@/views/ConsultantManagement/CounselorInfo.vue')
				},
				{
					path: '/LevelInfo',
					name: 'LevelInfo',
					component: () => import('@/views/ConsultantManagement/LevelInfo.vue')
				},
				{
					path: '/Advantage',
					name: 'Advantage',
					component: () => import('@/views/ConsultantManagement/Advantage.vue')
				},
				{
					path: '/Feeclassification',
					name: 'Feeclassification',
					component: () => import('@/views/ConsultantManagement/Feeclassification.vue')
				},
				{
					path: '/ChargingStandards',
					name: 'ChargingStandards',
					component: () => import('@/views/ConsultantManagement/ChargingStandards.vue')
				},
				//咨询师信息管理->评价管理
				{
					path: '/appraise',
					name: 'appraise',
					component: () => import('@/views/ConsultantManagement/Appraise.vue')
				},
				{
					path: '/MessageManagement',
					name: 'MessageManagement',
					component: () => import('@/views/ConsultantManagement/MessageManagement.vue')
				},
				{
					path: '/OrderManagement',
					name: 'OrderManagement',
					component: () => import('@/views/ConsultantManagement/OrderManagement.vue')
				},
				{
					path: '/AC',
					name: 'AC',
					component: () => import('@/views/ec/AC.vue')
				},
				{
					path: '/PM',
					name: 'PM',
					component: () => import('@/views/ec/PM.vue')
				},
				{
					path: '/QuestionBank',
					name: 'QuestionBank',
					component: () => import('@/views/ec/QuestionBank.vue')
				},
				{
					path: '/Results',
					name: 'Results',
					component: () => import('@/views/ec/Results.vue')
				},
				{
					path: '/Problem',
					name: 'Problem',
					component: () => import('@/views/pa/Problem.vue')
				},
				{
					path: '/Reply',
					name: 'Reply',
					component: () => import('@/views/pa/Reply.vue')
				},
				{
					path: '/Company',
					name: 'Company',
					component: () => import('@/views/system/Company.vue'),
				},
				{
					path: '/Menu',
					name: 'Menu',
					component: () => import('@/views/system/Menu.vue'),
				},
				{
					path: '/Role',
					name: 'Role',
					component: () => import('@/views/system/Role.vue'),
				},
				{
					path: '/User',
					name: 'User',
					component: () => import('@/views/system/User.vue'),
				},
				{
					path: '/ConsultingAnnouncement',
					name: 'ConsultingAnnouncement',
					component: () => import('@/views/ConsultingAnnouncement.vue'),
				},
				{
					path: '/manage',
					name: 'manage',
					component: () => import('@/views/manage.vue'),
				},
				{
					path: '/page',
					name: 'page',
					component: () => import('@/views/page.vue'),
				}, {
					path: '/Classification',
					name: 'Classification',
					component: () => import('@/views/Lesson/Classification.vue')
				},
				{
					path: '/Courseinformation',
					name: 'Courseinformation',
					component: () => import('@/views/Lesson/Courseinformation.vue')
				},
				{
					path: '/Video',
					name: 'Video',
					component: () => import('@/views/Lesson/Video.vue')
				}, {
					path: '/Evaluation',
					name: 'Evaluation',
					component: () => import('@/views/Lesson/Evaluation.vue')
				}, {
					path: '/Order',
					name: 'Order',
					component: () => import('@/views/Lesson/Order.vue')
				}
			]
		}
	],
})
router.beforeEach((to, from, next) => {
	const counter = useUserStore();
	if (to.path === '/login') {
		return next() // 放行
	}
	// 获取登录用户信息
	// const userInfo = localStorage.getItem('counter')
	if (counter.userInfo == '') {
		return next('/login')
	}
	next()
})
export default router